﻿package mortal.game.view.relive.parts
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class ReliveLocalPart extends GSprite
    {
        private var _shopItem:BaseItem;
        private var _box:GCheckBox;
        private var _bg:ScaleBitmap;
        private var _btn:GLabelButton;
        private var _secTimerView:SecTimerView;
        private var _vipTip:VipOpenTipsPanel;
        private var _callback:Function;
        private var _hasTimeOut:Boolean = false;

        public function ReliveLocalPart()
        {
            return;
        }// end function

        public function setLeftTime(param1:int, param2:Function = null) : void
        {
            var _loc_3:GTextFormat = null;
            if (this._hasTimeOut)
            {
                return;
            }
            this._callback = param2;
            if (this._secTimerView == null)
            {
                _loc_3 = GlobalStyle.textFormatHuang2;
                _loc_3.size = 12;
                this._secTimerView = UIFactory.secTimeView("[ss]", 202, 33, 120, 26, null, _loc_3);
                this._secTimerView.filters = [FilterConst.glowFilter];
            }
            this.addChild(this._secTimerView);
            this._btn.labelDx = -13;
            this._btn.updateLayout();
            this._btn.enabled = false;
            this._secTimerView.setLeftTime(param1);
            this._secTimerView.timeOutHandler = this.timeOutHandler;
            return;
        }// end function

        private function timeOutHandler() : void
        {
            this._hasTimeOut = true;
            this._btn.enabled = true;
            this._btn.labelDx = 0;
            this._btn.updateLayout();
            DisplayUtil.removeMe(this._secTimerView);
            var _loc_1:* = ShopConfig.instance.getFastBuyItemByCode(GameConst.RelivePropItemId);
            _loc_1.isUseGoldBuyGoldBind = true;
            _loc_1.num = 1;
            _loc_1.npcId = 0;
            var _loc_2:* = Cache.instance.vip.getLeftFreeTimesByType(EVipRecordType._EVipRecordTypeRelive);
            if (_loc_2 != 0 || ShopUtil.isEnougthMoney(_loc_1, true))
            {
                if (this._callback != null)
                {
                    this._callback.apply();
                }
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._hasTimeOut = false;
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem) as ShopSellItem;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._shopItem.itemCode = 180120001;
            this.addChild(this._shopItem);
            this._box = UIFactory.checkBox(Language.getString(21049), 0, 70, 120, 28, this);
            this._bg = UIFactory.bg(87, -2, 184, 24, this, ImagesConst.RegionTitleBg);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 16;
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21050), 108, -3, 220, 22, this, _loc_1));
            this._btn = UIFactory.gLabelButton(null, GLabelButton.gLoadingButton, ImagesConst.VipReCharge_upSkin, 95, 25, 156, 39, this);
            _loc_1 = GlobalStyle.textFormatHuang2;
            _loc_1.size = 14;
            this._vipTip = UIFactory.getUICompoment(VipOpenTipsPanel, 75, 65, this);
            this._vipTip.isShowLeftNum(true);
            this._vipTip.valueType = VipOpenTipsPanel.numberValue;
            this._vipTip.resetLevelTextPos(69, 9, 79, 9);
            this._vipTip.resetValueTextPos(200, 10, 240, 10);
            this._vipTip.bgUrl = ImagesConst.vipOpenTipsBg_mid;
            this._vipTip.vipType = EVipRecordType._EVipRecordTypeRelive;
            LoaderHelp.addResCallBack(ResFileConst.relivePanel, this.resGotHandler);
            this._btn.configEventListener(MouseEvent.CLICK, this.localReliveHandler);
            this._box.selected = PulseSharedObject.isTodayNotTips(TodayNoTipsConst.buyRevivalProp);
            this._box.configEventListener(Event.CHANGE, this.selectChangeHandler);
            return;
        }// end function

        private function selectChangeHandler(event:Event) : void
        {
            PulseSharedObject.save(TodayNoTipsConst.buyRevivalProp, this._box.selected);
            return;
        }// end function

        private function localReliveHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.Revival_ProRevival));
            return;
        }// end function

        private function resGotHandler() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._btn.label = ImagesConst.relive_LabelYDFH;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._hasTimeOut = false;
            this._shopItem.dispose(param1);
            this._shopItem = null;
            this._box.dispose(param1);
            this._box = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._btn.dispose(param1);
            this._btn = null;
            this._vipTip = null;
            if (this._secTimerView != null)
            {
                this._secTimerView.stop();
                this._secTimerView.dispose(param1);
                this._secTimerView = null;
            }
            return;
        }// end function

    }
}
